<?php
/**
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; version 3 of the License.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
*/

/**
 * Autoloader function. See PHP documentation.
 * @param string $classname
 * @return void
 */
$includedClasses = array();

function __autoload($classname)
{
	global $includedClasses;

	$classname = ltrim($classname, "\\");

	if (!in_array($classname, $includedClasses)) {
		if (preg_match("/^Core\\\/", $classname)) {
			$classPath = DIR_CORE . "/" . str_replace("\\", "/", preg_replace("/^Core/", "", $classname)) . ".php";
		} else {
			$classPath = DIR_LIB . "/" . str_replace("\\", "/", $classname) . ".php";
		}

		if (!file_exists($classPath) || !include_once($classPath)) {
			$method = CLASS_NOT_FOUND;
			$method("Class " . $classname . " could not be found." . E_USER_WARNING);
		}

		$includedClasses[] = $classname;
	}
}

?>